package com.itao.ds.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itao.ds.bean.User;
import com.itao.ds.mapper.UserMapper;
import org.springframework.stereotype.Service;

/**
 * @Author sjt
 * @CreateTime 2025/9/28 9:59
 */
@Service
public class UserService extends ServiceImpl<UserMapper, User> {

    @DS("master")
    public void saveUser(User user){
        save(user);
    }

    // 指定具体的数据源
//    @DS("slave")
//    public User getUser(Long id){
//        return getById(id);
//    }
    // 从请求头 dyn-ds 中获取数据源
    @DS("#header.dyn-ds") //
    public User getUser(Long id){
        return getById(id);
    }
}
